/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.yuhanginfo.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.yuhanginfo.common.config.Global;
import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.modules.sys.entity.EnquiryGoodsReply;
import com.yuhanginfo.modules.sys.service.EnquiryGoodsReplyService;

/**
 * 询价回复
 * @author yangs
 * @version 2017-11-23
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/enquiryGoodsReply")
public class EnquiryGoodsReplyController extends BaseController {

	@Autowired
	private EnquiryGoodsReplyService enquiryGoodsReplyService;
	
	@ModelAttribute
	public EnquiryGoodsReply get(@RequestParam(required=false) String id) {
		EnquiryGoodsReply entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = enquiryGoodsReplyService.get(id);
		}
		if (entity == null){
			entity = new EnquiryGoodsReply();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:enquiryGoodsReply:view")
	@RequestMapping(value = {"list", ""})
	public String list(EnquiryGoodsReply enquiryGoodsReply, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EnquiryGoodsReply> page = enquiryGoodsReplyService.findPage(new Page<EnquiryGoodsReply>(request, response), enquiryGoodsReply); 
		model.addAttribute("page", page);
		return "modules/sys/order/enquiryGoodsReplyList";
	}

	@RequiresPermissions("sys:enquiryGoodsReply:view")
	@RequestMapping(value = "form")
	public String form(EnquiryGoodsReply enquiryGoodsReply, Model model) {
		model.addAttribute("enquiryGoodsReply", enquiryGoodsReply);
		return "modules/sys/enquiryGoodsReplyForm";
	}

	@RequiresPermissions("sys:enquiryGoodsReply:edit")
	@RequestMapping(value = "save")
	public String save(EnquiryGoodsReply enquiryGoodsReply, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, enquiryGoodsReply)){
			return form(enquiryGoodsReply, model);
		}
		enquiryGoodsReplyService.save(enquiryGoodsReply);
		addMessage(redirectAttributes, "保存询价成功");
		return "redirect:"+Global.getAdminPath()+"/sys/enquiryGoodsReply/?repage";
	}
	
	@RequiresPermissions("sys:enquiryGoodsReply:edit")
	@RequestMapping(value = "delete")
	public String delete(EnquiryGoodsReply enquiryGoodsReply, RedirectAttributes redirectAttributes) {
		enquiryGoodsReplyService.delete(enquiryGoodsReply);
		addMessage(redirectAttributes, "删除询价成功");
		return "redirect:"+Global.getAdminPath()+"/sys/enquiryGoodsReply/?repage";
	}

}